/**
 * 
 */
package cn.java.innerclass;


/**
* 匿名内部类实现回调方法案例
* @author 攀博课堂
* @version v1.0
*/
public class VideoProcessor4 {
	
	//视频
	private Video video;
	
	public VideoProcessor4(Video video) {
		this.video = video;
	}
	
	public void printVideo() {
		System.out.println(video);
	}
	
	//处理结果
	private VideoProcessorResult videoProcessorResult;
	
	//处理方法，传入了ResultCallback对象
	public void process(ResultCallback resultCallback) {
		
		//创建任务对象
		VideoProcessorTask videoProcessorTask = new VideoProcessorTask();
		//启动任务
		videoProcessorTask.start(resultCallback);
	}
	
	//处理任务类
	private class VideoProcessorTask{
		
		//启动任务，接收到ResultCallback对象
		public void start(ResultCallback resultCallback) {
			System.out.println("启动任务进行视频处理...");
			printVideo();
			
			//处理完成得到处理结果
			videoProcessorResult  = new VideoProcessorResult(1,"成功","http://www.pbteach.com/1");
			
			System.out.println(videoProcessorResult);
			//进行方法回调
			if(resultCallback!=null) {
				//调用回调方法
				System.out.println("开始进行方法回调...");
				resultCallback.callback(videoProcessorResult);
			}
		}
		
		//终止任务
		public void cancel() {
			System.out.println("终止任务");
		}
	}
	
	
	
	
	//处理结果
	public class VideoProcessorResult{
		//结果处理代码，1表示成功，0表示失败
		private int code;
		//失败信息
		private String msg;
		//新视频地址
		private String newAddress;
		
		public VideoProcessorResult(int code,String msg,String newAddress) {
			this.code = code;
			this.msg = msg;
			this.newAddress = newAddress;
			
		}

		@Override
		public String toString() {
			return "VideoProcessorResult [code=" + code + ", msg=" + msg + ", newAddress=" + newAddress + "]";
		}
		
	}
	
	//内部接口，实现了对处理结果的进一步处理
	public interface ResultCallback{
		void callback(VideoProcessorResult videoProcessorResult);
	}

}
